package com.sky.task;

import com.sky.entity.Orders;
import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
@Slf4j
public class OrderTask {

    @Autowired
    OrderMapper orderMapper;

    @Scheduled(cron = "0 * * * * ?")
    public void processTimeoutOrder() {
        log.info("定时处理超时订单：{}", LocalDateTime.now());
        LocalDateTime localDateTime = LocalDateTime.now().minusMinutes(15);
        List<Long> ids=orderMapper.getTimeoutIds(Orders.PENDING_PAYMENT,localDateTime);
        if (ids!=null&&!ids.isEmpty()) orderMapper.updateStatusBatch(ids);
    }


//    @Scheduled(cron = "* * 0/2 * * ? ")
//    public void processDeliveryOrder(){
//        log.info("定时处理配送时间过长的订单：{}", LocalDateTime.now());
//
//    }
}
